package net.expectx.gw.service.impl;

import net.expectx.common.base.BaseResult;
import net.expectx.gw.mapper.SystemSettingMapper;
import net.expectx.gw.bean.SystemSetting;
import net.expectx.gw.service.SystemSettingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SystemSettingService实现
 * @author lijian
 * @date 2019/1/18
 */
@Service
public class SystemSettingServiceImpl extends BaseServiceImpl<SystemSetting> implements SystemSettingService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SystemSettingServiceImpl.class);

    @Autowired
    SystemSettingMapper systemSettingMapper;
    @Override
    public BaseResult insertSelective(SystemSetting record) {
        Map<String, Object>map=new HashMap<>(3);
        String msg;
        boolean flag=false;
        List<SystemSetting> SystemSettings =  systemSettingMapper.findByAttr("attr_name ='"+record.getAttrName()+"'", null);
        if (SystemSettings.isEmpty()){
            return super.insertSelective(record);
        }else{
            msg = "输入的配置已存在,请重新输入!";
        }
        return new BaseResult(false, msg, null);
    }

    @Override
    public BaseResult updateByPrimaryKeySelective(SystemSetting record) {
        Map<String, Object>map=new HashMap<>(2);
        String msg;
        boolean flag=false;
        List<SystemSetting> permissionSystems = systemSettingMapper.findByAttr("id not in('"+record.getId()+"') and attr_name ='"+record.getAttrName()+"'", null);
        if (permissionSystems.isEmpty()){
            return super.updateByPrimaryKeySelective(record);
        }else{
            msg = "输入的配置已存在,请重新输入!";
        }
        return new BaseResult(false, msg, null);
    }
}
